﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using cmsservice.Entity;
using cmsservice.DAL;
using System.Data;
using cmsservice.Common;

namespace cmsservice.BLL
{
    public class EMStockAnnounceBLL
    {
        EMStockAnnounceDAL dal = new EMStockAnnounceDAL();

        /// <summary>
        /// 获取个股公告信息
        /// </summary>
        /// <param name="code">股票代码</param>
        /// <returns></returns>
        public List<EMStockAnnounceModel> GetEMStockAnnounce(string code)
        {
            List<EMStockAnnounceModel> list = new List<EMStockAnnounceModel>();
            object o = Cache.Get("GetEMStockAnnounce" + code);
            if (o == null)
            {
                DataTable dt = dal.GetEMStockAnnounce(code);
                if (dt != null)
                {
                    int rowsCount = dt.Rows.Count;
                    for (int n = 0; n < rowsCount; n++)
                    {
                        EMStockAnnounceModel model = new EMStockAnnounceModel();
                        if (dt.Rows[n]["TextID"] != null && dt.Rows[n]["TextID"].ToString() != "")
                        {
                            model.TextID = dt.Rows[n]["TextID"].ToString();
                        }
                        if (dt.Rows[n]["AnnounceDate"] != null && dt.Rows[n]["AnnounceDate"].ToString() != "")
                        {
                            model.PublDate = dt.Rows[n]["AnnounceDate"].ToString();
                        }
                        model.Title = dt.Rows[0]["Title"].ToString();
                        model.TextContent = dt.Rows[n]["News"].ToString();
                        model.CategoryName2 = dt.Rows[n]["CategoryName2"].ToString();
                        model.CategoryName3 = dt.Rows[n]["CategoryName3"].ToString();
                        model.CategoryName4 = dt.Rows[n]["CategoryName4"].ToString();
                        list.Add(model);
                    }
                    if (list != null)
                    {
                        Cache.Add("GetEMStockAnnounce" + code, list, DateTime.Now.AddMinutes(5));
                    }
                }
            }
            else
                list = o as List<EMStockAnnounceModel>;
            return list;
        }
    }
}
